import config from '../../config'

type mapKey = keyof typeof config.images
export const image = new Map<mapKey, HTMLImageElement>()

// Object.entries()方法返回一个给定对象自身可枚举属性的键值对数组,
export const promises =  Object.entries(config.images).map(([key, value]) => {
  return new Promise(resolve => {
    const img = document.createElement('img')
    img.src = value
    img.onload = () => {
      image.set(key as mapKey, img)
      resolve(img)
    }
  })
})
